<template>
    <div id="OrdersTitle">
        <v-details :inputConfig="inputConfig" :detailData="inputData" :rules="rules" @pop="setData"
                   ref="input"></v-details>
    </div>
</template>

<script>
import details from 'commons/Detail'
import baseMixin from "@/mixins/BaseMixin";

export default {
    props: {
        inputData: {
            type: Object,
        }
    },
    mixins: [baseMixin],
    name: "OrdersTitle",
    data() {
        return {
            rules: {
                toloc: [
                    {required: true, validator: this.toloc, trigger: 'blur'},
                ],
                moveqty: [
                    {required: true, validator: this.moveqty, trigger: 'blur'},
                ],
            },
        }
    },
    computed: {
        inputConfig() {
            return [
                [
                    {
                        type: "input",
                        label: this.$t('config.shipper'),
                        props: "storerkey",
                        disabled: true
                    },
                    {
                        type: "input",
                        label: this.$t('config.sku'),
                        props: "sku",
                        disabled: true
                    },
                    {
                        type: "input",
                        label: this.$t('config.sku'),
                        props: "sku",
                        disabled: true
                    },
                    {
                        type: "input",
                        label: this.$t('bill.lot'),
                        props: "lot",
                        disabled: true
                    },
                    {
                        type: "input",
                        label: this.$t('config.num'),
                        props: "qtyavailqty",
                        disabled: true
                    }
                ],
                [
                    {
                        type: "input",
                        label: this.$t('outbound.fromloc'),
                        props: "fromloc",
                        disabled: true
                    },
                    {
                        type: "table",
                        label: this.$t('in.fromid'),
                        props: "fromid",
                        disabled: true,
                    },
                    {
                        type: "input",
                        label: this.$t('ex.fromtarewgt'),
                        props: "fromtarewgt",
                        disabled: true
                    },
                    {
                        type: "input",
                        label: this.$t('ex.fromnetwgt'),
                        props: "fromnetwgt",
                        disabled: true
                    },
                    {
                        type: "input",
                        label: this.$t('ex.fromgrosswgt'),
                        props: "fromgrosswgt",
                        disabled: true
                    },
                ],
                [
                    {
                        type: "table",
                        label: this.$t('config.toLoc'),
                        props: "toloc",
                        tableConfig: [
                            {
                                label: this.$t('config.loc'),
                                prop: "loc",
                                input: "input",
                            },
                            {
                                label: this.$t('common.type'),
                                prop: "locationtype",
                                input: "select",
                                options: this.getOptions("querycodeLkup/LOCTYPE")
                            },
                            {
                                label: this.$t('config.area'),
                                prop: "putawayzone",
                                input: "select",
                                options: this.getOptions("queryPutawayzoneDropDown")
                            },
                            {
                                label: this.$t('config.locFlag'),
                                prop: "locationflag",
                                input: "select",
                                options: this.getOptions("querycodeLkup/LOCFLAG")
                            },
                            {
                                label: this.$t('config.locCategory'),
                                prop: "locationcategory",
                                input: "select",
                                options: this.getOptions("querycodeLkup/LOCCATEGRY")
                            },
                            {
                                label: this.$t('config.loseId'),
                                prop: "loseid",
                                input: "select",
                                options: this.getOptions("querycodeLkup/YESNO")
                            },
                            {
                                label: this.$t('in.comminglelot'),
                                prop: "comminglelot",
                                input: "select",
                                options: this.getOptions("querycodeLkup/YESNO")
                            },
                            {
                                label: this.$t('config.commingleSku'),
                                prop: "comminglesku",
                                input: "select",
                                options: this.getOptions("querycodeLkup/YESNO")
                            },
                            {
                                label: this.$t('config.capacity'),
                                prop: "cubiccapacity",
                                input: "input",
                            }
                        ],
                        url: `/queryLoc/`
                    },
                    {
                        type: "input",
                        label: this.$t('in.toid'),
                        props: "toid",
                    },
                    {
                        type: "input",
                        label: this.$t('config.batchProp',{no:'01'}),
                        props: "lottable01",
                        disabled: true
                    },
                    {
                        type: "input",
                        label: this.$t('config.batchProp',{no:'02'}),
                        props: "lottable02",
                        disabled: true
                    },
                    {
                        type: "input",
                        label: this.$t('config.batchProp',{no:'03'}),
                        props: "lottable03",
                        disabled: true
                    },
                ],
                [
                    {
                        type: "input",
                        label: this.$t('out.moveqty'),
                        props: "moveqty",
                    },
                    {
                        type: "date",
                        label: this.$t('config.batchProp',{no:'04'}),
                        props: "lottable04",
                        disabled: true
                    },
                    {
                        type: "date",
                        label: this.$t('config.batchProp',{no:'05'}),
                        props: "lottable05",
                        disabled: true
                    },
                    {
                        type: "input",
                        label: this.$t('config.batchProp',{no:'06'}),
                        props: "lottable06",
                        disabled: true
                    },
                    {
                        type: "input",
                        label: this.$t('config.batchProp',{no:'07'}),
                        props: "lottable07",
                        disabled: true
                    },
                ]
            ]
        }
    },
    methods: {
        toloc(rule, value, callback) {
            if (value === '') {
                callback(new Error());
            } else {
                this.$api.get(`/queryLocCount/${value}`).then(res => {
                    
                        if (parseInt(res.bean) > 0) {
                            callback()
                        } else {
                            this.inputData[rule.field] = ""
                            this.$message.error(this.$t('msg.msg23') + value);
                            callback(new Error());
                        }
                }).catch(e => {
                    this.$message.error(e);
                    callback(new Error());
                })
            }
        },
        moveqty(rule, value, callback) {
            if (value === '') {
                callback(new Error());
            } else {
                var re = /^[0-9]*$/;
                let te = value;
                let flag = re.test(te)
                if (flag) {
                    if (value < 0) {
                        this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'))
                        this.inputData[rule.field] = ""
                        callback(new Error());
                    } else {
                        callback();
                    }
                } else {
                    this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'))
                    this.inputData[rule.field] = ""
                    callback(new Error());
                }
            }
        },
        setData(data, id, close, listId) {
            this.inputData.toloc = data.loc;
            close(false);
        }
    },
    mounted() {

    },
    watch: {},
    components: {
        'v-details': details
    }
}
</script>

<style scoped>

</style>
